#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
int t,pan[N][N],pan1[N],place[N];
int d[N],v[N],a[N],p[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&t);
    while(t--){
        int n,m,ans1=0,l,v1;
        scanf("%d%d%d%d",&n,&m,&l,&v1);
        for(int i=1;i<=n;i++) scanf("%d%d%d",&d[i],&v[i],&a[i]);
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
            pan1[i]=0;
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                pan[i][j]=0;
            }
        }
        for(int i=1;i<=n;i++){
            int temp=0;
            if(a[i]==0){
                if(v[i]<=v1) continue;
                else{
                    for(int j=1;j<=m;j++){
                        if(d[i]<=p[j]){
                            pan[i][j]++;pan1[j]++;
                            if(temp==0){
                                    ans1++;
                                    temp=1;
                                }
                        }
                    }
                }
            }
            else{
                if(a[i]>0){
                    double x=(v1*v1-v[i]*v[i])/(2*a[i]);
                    if(v[i]<=v1){
                        for(int j=1;j<=m;j++){
                            if(p[j]>=d[i]+x){
                                pan[i][j]++;pan1[j]++;
                                if(temp==0){
                                    ans1++;
                                    temp=1;
                                }
                            }
                        }
                    }
                    else{
                        for(int j=1;j<=m;j++){
                            if(p[j]>d[i]){
                                pan[i][j]++;pan1[j]++;
                                if(temp==0){
                                    ans1++;
                                    temp=1;
                                }
                            }
                        }
                    }
                }
                else{
                    double x=(v1*v1-v[i]*v[i])/(2*a[i]);
                    if(v[i]<=v1) continue;
                    else{
                        for(int j=1;j<=m;j++){
                            if(p[j]>=d[i]&&p[j]<=d[i]+x){
                                pan[i][j]++;pan1[j]++;
                                if(temp==0){
                                    ans1++;
                                    temp=1;
                                }
                            }
                        }
                    }
                }
            }
        }
        for(int i=1;i<=n;i++) place[i]=0;
        for(int i=1;i<=n;i++){
            if(place[i]==0){
                int cnt=0;
                for(int j=1;j<=m;j++){
                    if(pan[i][j]==1){
                        if(pan1[j]>cnt){
                            cnt=pan1[j];
                            p[j]=-1;
                            for(int k=1;k<=n;k++){
                                if(pan[k][j]==1) place[k]=1;
                            }
                        }
                    }
                }
            }
        }
        int ans2=0;
        for(int i=1;i<=m;i++){
            if(p[i]!=-1) ans2++;
        }
        printf("%d %d",ans1,ans2);
    }
    return 0;
}
